package com.gzhu.knowledgeAdmin.parammanage;


import com.gzhu.knowledgeAdmin.common.enums.ParamTypeEnum;
import com.gzhu.knowledgeAdmin.common.exception.BusinessException;
import com.gzhu.knowledgeAdmin.common.result.ErrorCode;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Component
public class ParamCRUDRegistry {

    @Resource
    private TemplateTypeParamCRUD templateTypeParamCRUD;

    @Resource
    private AnswerTypeParamCRUD answerTypeParamCRUD;

    @Resource
    private RecorderParamCRUD recorderParamCRUD;

    @Resource
    private VariableParamCRUD variableParamCRUD;

    @Resource
    private DenoiseLevelParamCRUD denoiseLevelParamCRUD;

    @Resource
    private RecognitionModeParamCRUD recognitionModeParamCRUD;

    @Resource
    private CategoryParamCRUD categoryParamCRUD;

    @Resource
    private IntentionJudgeConditionParamCRUD intentionJudgeConditionParamCRUD;

    private Map<String, ParamCRUD> typeDataSourceMap;

    @PostConstruct
    public void doInit() {
        typeDataSourceMap = new HashMap();
        typeDataSourceMap.put(ParamTypeEnum.TEMPLATE_TYPE.getValue(), templateTypeParamCRUD);
        typeDataSourceMap.put(ParamTypeEnum.ANSWER_TYPE.getValue(), answerTypeParamCRUD);
        typeDataSourceMap.put(ParamTypeEnum.RECORDER.getValue(), recorderParamCRUD);
        typeDataSourceMap.put(ParamTypeEnum.VARIABLE.getValue(), variableParamCRUD);
        typeDataSourceMap.put(ParamTypeEnum.DenoiseLevel.getValue(), denoiseLevelParamCRUD);
        typeDataSourceMap.put(ParamTypeEnum.RecognitionMode.getValue(), recognitionModeParamCRUD);
        typeDataSourceMap.put(ParamTypeEnum.CATEGORY.getValue(), categoryParamCRUD);
        typeDataSourceMap.put(ParamTypeEnum.INTENTION_JUDGE_CONDITION.getValue(), intentionJudgeConditionParamCRUD);
    }

    public Map<String, ParamCRUD> getTypeDataSourceMap() {
        return this.typeDataSourceMap;
    }

    public ParamCRUD getParamCURDByType(String type) {
        if (typeDataSourceMap == null) {
            return null;
        }
        ParamCRUD paramCRUD = typeDataSourceMap.get(type);
        if (paramCRUD == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        return paramCRUD;
    }
}
